package com.syl.starter.mp.generate;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import lombok.Getter;
import lombok.experimental.Accessors;

/**
 * 最简单的代码生成
 * @author syl
 * @create 2019-05-20 23:06
 **/
@Accessors(chain = true)
public class SimpleCodeGenerate extends BaseCodeGenerate {

    @Getter
    private SuperCodeGenerate superCodeGenerate;

    /**
     * 以当前项目路径构造  最简单
     * @param author 作者
     */
    public SimpleCodeGenerate(String author){
        this(author, null);
    }

    /**
     * 以当前项目路径构造
     * @param author 作者
     * @param idType 主键生成策略
     */
    public SimpleCodeGenerate(String author, IdType idType){
        this(author, idType, false);
    }

    /**
     * 以当前项目路径构造
     * @param author 作者
     * @param idType 主键生成策略
     * @param moreDataSource 是否多数据源
     */
    public SimpleCodeGenerate(String author, IdType idType, boolean moreDataSource){
        this(System.getProperty("user.dir"), author, idType, moreDataSource);
    }

    /**
     * @param projectPath 目标项目路径
     * @param author 作者
     * @param idType 主键生成策略
     * @param moreDataSource 是否多数据源
     */
    public SimpleCodeGenerate(String projectPath, String author, IdType idType, boolean moreDataSource){
        superCodeGenerate = new SuperCodeGenerate(projectPath, author)
            .setMoreDataSource(moreDataSource)
            .setIdType(idType)
        ;
    }

    @Override
    public void start() throws Exception {
        superCodeGenerate.start();
    }

    @Override
    public SimpleCodeGenerate setProjectPath(String projectPath) {
        superCodeGenerate.setProjectPath(projectPath);
        return this;
    }

    @Override
    public SimpleCodeGenerate setTableNames(String... tableNames) {
        superCodeGenerate.setTableNames(tableNames);
        return this;
    }

    /**
     * 设置去除表名称前缀
     * @param tablePrefixWipes
     * @return
     */
    @Override
    public SimpleCodeGenerate setTablePrefixWipes(String... tablePrefixWipes) {
        superCodeGenerate.setTablePrefixWipes(tablePrefixWipes);
        return this;
    }

    @Override
    public SimpleCodeGenerate setDataSourceConfig(DataSourceConfig dataSourceConfig) {
        superCodeGenerate.setDataSourceConfig(dataSourceConfig);
        return this;
    }

    /**
     * 设置包配置
     * @param packageConfig
     * @return
     */
    @Override
    public SimpleCodeGenerate setPackageConfig(PackageConfig packageConfig) {
        superCodeGenerate.setPackageConfig(packageConfig);
        return this;
    }

}
